package saas.dev.webflux.webflux.router;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import saas.dev.webflux.webflux.handler.GoodHandler;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

/**
 * @ClassName : GoodRouter
 * @Author : y1
 * @Date: 2022/3/25 14:07
 * @Description :
 */
@Configuration
public class GoodRouter {
    @Bean
    public RouterFunction<ServerResponse> route(GoodHandler goodHandler) {
        return RouterFunctions
                .route(GET("/good")
                        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), goodHandler::hello)
//                .andRoute(GET("/goods")
//                        .and(RequestPredicates.accept(MediaType.TEXT_EVENT_STREAM)), );
                .andRoute(GET("/date"), goodHandler::echo);
    }
}
